<template>
  <div>
    <jsscom-heard/>
    <div class="cons">
      <div class="pu-con">
        <div class="gy-cons">
          <gy-com-left
            @onLeftTab="onLeftTab"
            :leftTitle="leftTitle"
            :navList="navList"
            :navTopList="navTopList"
            :curIndex="curIndex"
            :topIndex="topIndex"
          />
          <div class="gy-r">
            <div class="gy-r-1">
              <p>{{ leftTitle1 }}</p>
            </div>
            <zixun-right :zxList="zxList" v-if="curIndex == 0"/>
            <tiku-right :tikuList="tikuList" v-if="curIndex == 1"/>
            <chaxun-right v-if="curIndex == 2" :topIndex="topIndex"/>
          </div>
        </div>
      </div>
    </div>
    <com-foot></com-foot>
  </div>
</template>

<script>
  import _ from "underscore";
  import jsscomHeard from "@/components/jsscom-heard";
  import comFoot from "@/components/com-foot";
  import gyComLeft from "./zypx-left";
  import zixunRight from "./zixun-right";
  import tikuRight from "./tiku-right";
  import chaxunRight from "./chaxun-right";

  export default {
    components: {
      jsscomHeard,
      comFoot,
      gyComLeft,
      zixunRight,
      tikuRight,
      chaxunRight,
    },
    data() {
      return {
        leftTitle: "专业培训",
        topTitle: "",
        leftTitle1: "",

        topIndex: 0,
        curIndex: 0,
        navTopList: [],
        navList: [
          {
            id: 0,
            name: "培训资讯",
          },
          {
            id: 1,
            name: "题库",
          },
          {
            id: 2,
            name: "证书查询",
          },
        ],
        zxList: [],
        tikuList: [],
        param: {},
      };
    },
    created() {
      this.getZypxMenu();
    },
    mounted() {
    },
    methods: {
      async getZypxMenu() {
        const res = await this.$store.dispatch("news/getZypxMenu");
        this.navTopList = res;
        this.param = this.navTopList[this.curIndex];
        this.leftTitle1 = this.param.title;
        this.getZypxList(1);
        console.log(res);
      },
      onLeftTab(e) {
        console.log(e);
        this.curIndex = e.index;
        this.topIndex = e.topIndex;
        this.param = this.navTopList[this.topIndex];
        this.leftTitle1 = this.param.title;
        console.log(this.param);
        this.getZypxList(1);
      },

      async getZypxList(val) {
        var that =this
        const data = {
          currentPage: val,
          pageSize: 10,
          rootId: this.param.id,
        };
        const res = await this.$store.dispatch("news/getZypxList", data);
        var arr = res.page.list;
        that.tikuList=[]
        that.zxList=[]
        arr.forEach(function (info, index) {

          var type = info.type
          if (type==2) {
            that.tikuList.push(info)
          }else{
            that.zxList.push(info)
          }
        });
        // this.zxList = res.page.list.slice(0, 1);
        this.totalSum = res.totalCount;
        this.newsList = res.list;
      },
    },
  };
</script>

<style scoped>
  @import "./hyzixun.css";
</style>
